Skip to main content

FrontSubmit

Wolfram Kernel
Execution environment
Notebook`Editor`Kernel`FrontSubmitService`
Context

Sends an expression to be executed on WLJS Interpreter (frontend / browser)

FrontSubmit[expr_, opts___]

Options

"Window"

specifies a window socket, to which an expression will be sent. Use CurrentWindow to fetch a window object from the evaluation context.

warning

Be aware of a context loss in a case of an handler function called from outside. For example with Parallel kernels or SetTimeout one have to explicitly provide a WindowObj

With[{win = CurrentWindow[]},
(* Current evaluation context *)

SetTimeout[
(* Evaluation context lost!!! *)
FrontSubmit[Alert["Boom"], "Window"->win]
, 3000];

"Hi there!"
]
tip

Please have a look at this guide - Advanced animation

Examples

Calling an WLJS (or Frontend) function

FrontSubmit[Alert["Hello World!"]]

which will produce a pop-up modal window.

Or to call a custom-defined Javascript function

cell 1
core.ShowReversed = async (args, env) => {
const text = await interpretate(args[0], env);
alert(text..split("").reverse().join(""));
}
cell 2
FrontSubmit[ShowReversed["Must be reversed..."]];

Append objects to a static graph

We can append anything to a graphics canvas without reevaluation of a cell

cell 1
scene = FrontInstanceReference[];
Plot[x, {x,0,1}, Epilog->{scene}]

and then

cell 2
FrontSubmit[Arrow[RandomReal[{0,1}, {2,2}]], scene]

to append an arrow to an existing graph.

Controlling ViewBox

A typical graphics figure is usually a ViewBox. Here we can reference it using FrontInstanceReference

plot.= FrontInstanceReference[];
Plot[x, {x,0,1}, Epilog->{plot}]

and then we can destroy it and replace with some other text

FrontSubmit[ViewBox`OuterExpression["Hello World"], plot]